﻿using DGZImp.MdsProject.Base;
using DGZImp.MdsProject.Devices.Base;
using DGZImp.MdsProject.Devices.Helper;
using DGZImp.MdsProject.Devices.Models;
using Microsoft.AspNetCore.Hosting.Server;
using Newtonsoft.Json;
using Nomad.Iot;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DGZImp.MdsProject.Devices
{
    /// <summary>
    /// 输送线
    /// </summary>
    public class Conveyor : PlcDevice<ConveyorData>
    {
        public Conveyor(string id, string name, IIotServe serve, List<PlcDataMapItem> maps) : base(id, name, serve, maps)
        {
        }

        [MdsAction("发送命令", "直接发送输送线指令")]
        public async Task<OperateResult> SendCommandAsync([MdsParameter("指令")] ConveyorCommandEnum Command)
        {
            return await WriteDataToPlc(new List<PlcDataWriteItem> {
                new(){ PropName = nameof(ConveyorData.Command), Value = Command }
            });
        }
    }

    public class ConveyorData
    {
        [Description("01.心跳")]
        public int Heartbeat { get; set; }

        [Description("02.编号")]
        public int No { get; set; }

        [Description("03.状态")]
        public ConveyorStatusEnum Status { get; set; }

        [Description("04.错误码")]
        public int Error { get; set; }

        [Description("05.光电遮挡")]
        public GoodsStatusEnum IsFull { get; set; }

        [Description("06.光电遮挡2")]
        public GoodsStatusEnum IsFullTwo { get; set; }

        [Description("07.任务号")]
        public int TaskNo { get; set; }

        [Description("08.起点")]
        public int StartPos { get; set; }

        [Description("09.终点")]
        public int EndPos { get; set; }

        [Description("10.称重数据")]
        public double Weight { get; set; }

        [Description("11.扫码数据")]
        public string Barcode { get; set; }

        [Description("80.写入指令")]
        public ConveyorCommandEnum Command { get; set; }

        [Description("81.写入故障")]
        public int SendError { get; set; }

        [Description("99.刷新时间")]
        public string RefreshTime { get; set; }
    }

}
